/**
 * Created with JetBrains WebStorm.
 * User: rren
 * Date: 04/09/13
 * Time: 10:52
 * To change this template use File | Settings | File Templates.
 */


exports.parseRange = function(str, size) {

    str = str.slice(str.indexOf('=')+1);

    if (str.indexOf(',') != -1) {
        return;
    }

    var range = str.split('-');
    var start = parseInt(range[0], 10);
    var end = parseInt(range[1], 10);

    //case: -100
    if (isNaN(start)) {
        start = size - end;
        end = size -1;
    } else if (isNaN(end)){
    //case 100-
        end = size -1;
    }

    //Invalid
    if(isNaN(start) || isNaN(end) || start > end || end > size) {
        return;
    }

    //console.log(start+"-"+end);
    return {start: start, end: end};
}